package com.gonsin.i18n.logic.machine;

import com.gonsin.i18n.logic.models.LanguageModel;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 所有支持的语言列表
 */
public enum Languages {

    zh("zh-cn", "中文", "中文"),
    en("en", "英语", "English"),
//    yue("yue", "粤语", ""),
    jp("jp", "日语", "日本語"),
    kor("kor", "韩语", "한국어"),
    fra("fra", "法语", "Français"),
    spa("spa", "西班牙语", "Español"),
    th("th", "泰语", "ไทย"),
    ara("ara", "阿拉伯语", "العربية"),
    ru("ru", "俄语", "Русский"),
    pt("pt", "葡萄牙语", "Português"),
    de("de", "德语", "Deutsch"),
    it("it", "意大利语", "Italiano"),
    el("el", "希腊语", "Ελληνικά"),
    nl("nl", "荷兰语", "Nederlands"),
    pl("pl", "波兰语", "Polski"),
    bul("bul", "保加利亚语", "Български"),
    est("est", "爱沙尼亚语", "Eesti"),
    dan("dan", "丹麦语", "Dansk"),
    fin("fin", "芬兰语", "Suomi"),
    cs("cs", "捷克语", "Čeština"),
    rom("rom", "罗马尼亚语", "Română"),
    slo("slo", "斯洛文尼亚语", "Slovenščina"),
    swe("swe", "瑞典语", "Svenska"),
    hu("hu", "匈牙利语", "Magyar"),
    cht("cht", "繁体中文", "繁體中文"),
    vie("vie", "越南语", "Tiếng Việt"),

    ;

    /**
     * 语言的关键词
     */
    private String lang;

    /**
     * 语言的中文标题
     */
    private String title;

    /**
     * 这个语言在该语言下的标题
     */
    private String selfTitle;

    Languages(String lang, String title, String selfTitle) {
        this.lang = lang;
        this.selfTitle = selfTitle;
        this.title = title;
    }

    public String getLang() {
        return lang;
    }

    public String getTitle() {
        return title;
    }

    public String getSelfTitle() {
        return selfTitle;
    }

    /**
     *
     */
    public static List<LanguageModel> list(){
        return Arrays.stream(Languages.values()).map(l -> {
            LanguageModel model = new LanguageModel();
            model.setLang(l.lang);
            model.setTitle(l.title);
            model.setSelfTitle(l.selfTitle);
            return model;
        }).collect(Collectors.toList());
    }


    static Map<String, Languages> map = new HashMap<>();
    static {
        for(Languages l : Languages.values()){
            map.put(l.lang, l);
        }
    }
    public static Languages get(String lang){
        lang = lang.toLowerCase(Locale.ROOT);
        return map.get(lang);
    }
}
